package com.vdong.interactive.course.web.controller;

import com.github.pagehelper.PageInfo;
import com.vdong.interactive.course.common.enums.ApiContract;
import com.vdong.interactive.course.common.supper.SupperController;
import com.vdong.interactive.course.entity.dto.PeddleChoiceCourseListDTO;
import com.vdong.interactive.course.entity.po.CourseDetailPO;
import com.vdong.interactive.course.entity.po.PeddleGoodsChoicePO;
import com.vdong.interactive.course.service.CourseService;
import io.swagger.annotations.*;
import org.lamb.framework.common.userDTO.AccountSystemUserInfoDTO;
import org.lamb.framework.core.security.LambPrincipalFactoryContainer;
import org.lamb.framework.core.templete.LambResponseTemplete;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;

/**
 * 学兽课程
 */
@Api(description = "学兽课程",tags = "学兽课程")
@RestController
@RequestMapping("/goods/course")
public class CourseController extends SupperController {

    @Resource
    private CourseService courseService;

    @ApiOperation(value = "选择分销课程列表(商户)" ,  notes="选择分销课程列表(商户)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courseName", value = "课程名称", paramType = "query", dataType = "String"),
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功",response = LambResponseTemplete.class)
    })
    @RequestMapping(value= ApiContract.getGoodsChoice,method = RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> getGoodsChoice(@RequestBody PeddleGoodsChoicePO po){
        AccountSystemUserInfoDTO systemUser = LambPrincipalFactoryContainer.getAccountSystemUser();
        PageInfo<PeddleChoiceCourseListDTO> pageInfo = courseService.getGoodsChoicePage(Long.valueOf(LambPrincipalFactoryContainer.getAccountSystemUser().getSysUserId()),Long.parseLong(systemUser.getPlatformInsideId()),po.getCourseName(),po.getPage(),po.getPageSize());
        return returning(pageInfo);
    }

    @ApiOperation(value = "课程详情(商户)" ,  notes="课程详情(商户)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courseId", value = "课程名称", paramType = "query", dataType = "int"),
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功",response = LambResponseTemplete.class)
    })
    @RequestMapping(value= ApiContract.getCourseDetail,method = RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> getCourseDetail(@RequestBody CourseDetailPO po){
        AccountSystemUserInfoDTO systemUser = LambPrincipalFactoryContainer.getAccountSystemUser();
        return returning(courseService.getCourseDetail(po.getCourseId(),Long.parseLong(systemUser.getPlatformInsideId())));
    }
}
